package com.wukong.servlet;
/* author: 悟空非空也（B站/知乎/公众号） */
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author wukong
 */
public class HelloWorld  extends HttpServlet{
    /**
     * http协议 ： 请求 响应
     * 请求： 请求头 请求体
     * 响应： 响应头 响应体
     * 请求方式
     * get  用于查询
     * post  添加
     * delete  删除
     * put   修改
     * 请求方式：
     * get
     *
     */
    /**
     * 处理get请求
     * @param request
     * @param response
     * @throws IOException
     * @throws ServletException
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException
    {
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        // 在浏览器上输出信息
        // servlet  实现了 在java代码中嵌套 html
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>1183902076</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>1183902076</h1>");
        out.println("<h2>1183902076</h2>");
        out.println("</body>");
        out.println("</html>");
    }

    /**
     * 请求方式： post  --> 添加资源到服务器
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       this.doGet(req, resp);
    }

    /**
     *  请求方式put  -->修改服务器中资源信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       this.doGet(req, resp);
    }

    /**
     *  请求方式 delete --> 删除服务器中资源
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }


}
